package gui;

//import org.noos.xing.mydoggy.plaf.ui.util.SwingUtil;

import jsonobj.LoginInfo;
import jsonobj.RegisterInfo;
import main.ClientFunctions;
import utils.Msg;

/**
*
* @author simon
*/
public class RegisterPanel extends javax.swing.JFrame {
	javax.swing.JFrame frame;
   /** Creates new form Register */
   public RegisterPanel() {
       initComponents();
      // SwingUtil.centrePositionOnScreen(this);
       this.frame = this;
   }

   /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">
   private void initComponents() {

       jButton1 = new javax.swing.JButton();
       userTxt = new javax.swing.JTextField();
       passTxt = new javax.swing.JPasswordField();
       emailTxt = new javax.swing.JTextField();
       jLabel1 = new javax.swing.JLabel();
       jLabel2 = new javax.swing.JLabel();
       jLabel3 = new javax.swing.JLabel();

       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

       jButton1.setText("Submit");

       jLabel1.setText("username:");

       jLabel2.setText("password:");

       jLabel3.setText("email:");

       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
       getContentPane().setLayout(layout);
       layout.setHorizontalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(26, 26, 26)
               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addComponent(userTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                   .addGroup(layout.createSequentialGroup()
                       .addComponent(jLabel1)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                   .addGroup(layout.createSequentialGroup()
                       .addComponent(jLabel2)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 85, javax.swing.GroupLayout.PREFERRED_SIZE))
                   .addComponent(passTxt, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                   .addGroup(layout.createSequentialGroup()
                       .addComponent(jLabel3)
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                   .addGroup(layout.createSequentialGroup()
                       .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                           .addComponent(jButton1)
                           .addComponent(emailTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE))
                       .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 4, javax.swing.GroupLayout.PREFERRED_SIZE)))
               .addGap(42, 42, 42))
       );
       layout.setVerticalGroup(
           layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
           .addGroup(layout.createSequentialGroup()
               .addGap(30, 30, 30)
               .addComponent(jLabel1)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addComponent(userTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
               .addComponent(jLabel2)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
               .addComponent(passTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
               .addComponent(jLabel3)
               .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addComponent(emailTxt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addGap(18, 18, 18)
               .addComponent(jButton1)
               .addGap(44, 44, 44))
       );
       
       jButton1.addMouseListener(new java.awt.event.MouseAdapter() {

			public void mouseClicked(java.awt.event.MouseEvent evt) {
				class doLogin extends Thread {
					public void run() {
						try {
							//jButton1.setEnabled(false);
							if(ClientFunctions.Register(new RegisterInfo(userTxt.getText(),new String(passTxt.getPassword()),emailTxt.getText())))
								frame.setVisible(false);
							//else jButton1.setEnabled(true);
						} catch (Exception e) {
							e.printStackTrace();
							
						}
					}
				}
				new doLogin().start();
			}
		});
       utils.Utils.centrePositionOnScreen(this);
       pack();
   }// </editor-fold>

   /**
   * @param args the command line arguments
   */
   public static void showPanel() {
       java.awt.EventQueue.invokeLater(new Runnable() {
           public void run() {
        	   new RegisterPanel().setVisible(true);
           }
       });
   }

   // Variables declaration - do not modify
   private javax.swing.JButton jButton1;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JLabel jLabel2;
   private javax.swing.JLabel jLabel3;
   private javax.swing.JTextField userTxt;
   private javax.swing.JPasswordField passTxt;
   private javax.swing.JTextField emailTxt;
   // End of variables declaration

}
